def prime(a):
    f=True
    for k in range(2,int(x**0.5) + 1):
        if a % k==0:
            f=False
            break
    return f
b=int(input())
if len(str(b))!=4:
    print(0)
else:
    max1=0
    for i in range(len(str(b)):
                   for j in range(i+1, len(str(b)+1):
                                  numb=int(str(b)[i:j])
if prime(numb):
                max1 = max(max1, numb)
    print(max1)
